<?php
session_start();
if (!isset($_SESSION['username'])) {
    $_SESSION['username'] = 'Гость';
    $_SESSION['role'] = 'guest';
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = htmlspecialchars($_POST['name']);
    $phone = htmlspecialchars($_POST['phone']);
    $address = htmlspecialchars($_POST['address']);
    $description = htmlspecialchars($_POST['description']);
    
    echo "<script>alert('Ваша заявка успешно отправлена'); window.location.href = 'index.php';</script>";
    exit();
}
?>

<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>ESHOP | Вызвать специалиста</title>
    <link rel="icon" type="image/png" sizes="32x32" href="/images/other/r-favicon-32x32.png">
    <link rel="stylesheet" href="/css/main_style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
</head>
<body>
    <div class="container">
        <header>
            <div class="header-top">
                <div class="header-title">
                    <h1><i>ESHOP</i></h1>
                    <h3>Магазин бытовой электроники</h3>
                </div>
                <div class="header-icons">
                    <div class="user-info">
                        <span><?php echo htmlspecialchars($_SESSION['username']); ?></span>
                        <div class="icon-container" onclick="openProfile()">
                            <i class="fas fa-user"></i>
                        </div>
                        <?php if ($_SESSION['role'] === 'admin'): ?>
                            <a href="admin_panel.php" class="icon-container" title="Администраторская панель">
                                <i class="fas fa-tools"></i>
                            </a>
                        <?php endif; ?>
                        <div class="icon-container" onclick="openCart()">
                            <i class="fas fa-shopping-cart"></i>
                            <span id="cartIndicator" class="cart-indicator"></span>
                        </div>
                    </div>
                </div>
            </div>
        </header>

        <section id="callSpecialistSection">
            <h2>Вызвать специалиста по установке техники</h2>
            <form id="callSpecialistForm" method="post">
                <label for="name">Имя:</label>
                <input type="text" id="name" name="name" required>
                
                <label for="phone">Телефон:</label>
                <input type="text" id="phone" name="phone" required>
                
                <label for="address">Адрес:</label>
                <input type="text" id="address" name="address" required>
                
                <label for="description">Описание задачи:</label>
                <textarea id="description" name="description" rows="4" required></textarea>
                
                <button type="submit">Отправить заявку</button>
            </form>
        </section>

        <footer>
            <div class="footer-container">
                <div class="footer-info">
                    <span>Контакты:</span>
                    <span>пер.Измаильский , 41, г. Ростов-на-Дону, Россия</span>
                    <span>+7 (988) 541-12-09</span>
                    <span>info@eshop.ru</span>
                    <a href="call_specialist.php">Вызвать специалиста по установке техники</a>
                </div>
            </div>
        </footer>
    </div>
    <script>
        function openProfile() {
            if (isLoggedIn) {
                window.location.href = 'profile.php'; 
            } else {
                window.location.href = 'login.php'; 
            }
        }

        function openCart() {
            if (isLoggedIn) {
                window.location.href = 'cart.php';
            } else {
                window.location.href = 'login.php'; 
            }
        }
    </script>
</body>
</html>
